/**
 * 在线客服渠道归属
 * 渠道队列: 
 *    14--官网/续保 
 *    17--CPS、百度车险等指定渠道
 * */
var baseServiceOnlineUrl = "http://im.95590.cn:7003/EliteWebChat/jsp/common/visitorEnter.html";

function serviceOnlineByChannel(name){
   var utm_source = findUtmSource();
   if(utm_source!=""){//CPS、百度车险等指定渠道
	   var param = {
		   "userResource": $.trim(utm_source) 
	   }
	   var _action = Newtouch.context+"/view/global/DistrictAction.jsp.getUserResourceByresouceValue";
	   Newtouch.Ajax.sendParams(param,_action,function(data){
			   if(data.projName!=null&&data.projName!=""){
				   var queueId = 14;
//				   if(data.projName == "网销快速报价"){//默认渠道
//					   queueId = 14;
//				   }
				   window.open(baseServiceOnlineUrl+"?queueId="+queueId+"&urlFrom="+encodeURIComponent(data.projName),"_blank");
			   }
		   },function(error){
		    alert("渠道来源查询出错！"+error);
	   });	   
   }else if("xinBao"==$.trim(name) || "xuBao"==$.trim(name)){//新保 或 续保(PS:新保和续保有公用页面的情况， 此时都按新保传值;)
	   var CN = "xinBao"==$.trim(name)?"官网":"续保";
	   window.open(baseServiceOnlineUrl+"?queueId=14&urlFrom="+encodeURIComponent($.trim(CN)),"_blank");
	   return;
   }
}

/**
 * 从url, id为"utm_source"的input, name为"utm_source"的input中查找utm_source.
 * 优先级从高到低： url--》id为"utm_source"的input --》name为"utm_source"的input中查找utm_source.
 * */
function findUtmSource(){
	var utm_source = "";
	//从url里查找
	var params =  location.search.substring(1);
	if(params.indexOf("utm_source")!=-1){
		 var list = params.split("&");
		 for(var i=0;i<list.length;i++){
			 if(list[i].indexOf("utm_source")!=-1){
				 utm_source = list[i].split("=")[1];
			 }
		 }
	}
	if(utm_source!=""){
		return decodeURI(utm_source);//ps: 注意url编码的中文转码
	}
	//从页面中查找(id或name为utm_source) ps: 暂不支持获取子页面里的utm_source
	if($("#utm_source").length>0&&$($("#utm_source")[0]).val()!=""){
		utm_source = $($("#utm_source")[0]).val();
		return utm_source;
	}
	if($("input[name='utm_source']").length>0&&$($("input[name='utm_source']")[0]).val()!=""){
		utm_source = $($("input[name='utm_source']")[0]).val();
		return utm_source;
	}
	return utm_source;
}
